<?php

namespace Redis;

use think\Config;
use think\Env;

class RdsModel
{
    private static $_instance;
    public $redis;
    protected $conf;

    public function __construct($_config = NULL)
    {
        $this->conf = [
            'host'  => Env::get('redis.host', '127.0.0.1'),
            'port'  => Env::get('redis.port', '6379'),
            'pwd'  => Env::get('redis.pwd', ''),
        ];
        $this->redis = new \Redis();
        $this->redis->connect($this->conf['host'], $this->conf['port']);
        if (isset($this->conf['pwd']) && $this->conf['pwd']) {
            $this->redis->auth($this->conf['pwd']);
        }
    }

    public static function getInstance()
    {
        if (!self::$_instance instanceof self) {
            self::$_instance = new self();
        }
        return self::$_instance;
    }
}
